package com.example.helloworld

import android.os.Bundle
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // 创建一个 LinearLayout
        val linearLayout = LinearLayout(this)

        // 设置线性布局的布局方向为垂直
        linearLayout.orientation = LinearLayout.VERTICAL

        // 设置 Activity 的内容视图为这个 LinearLayout
        setContentView(linearLayout)

        val textView = TextView(this)

        textView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
        textView.textSize =30F
        textView.text =getString(R.string.textView)
        linearLayout.addView(textView)

        val button =Button(this)
        button.width = ViewGroup.LayoutParams.MATCH_PARENT
        button.height = ViewGroup.LayoutParams.WRAP_CONTENT
        button.text=getString(R.string.button)
        linearLayout.addView(button)

        setContentView(linearLayout)

        button.setOnClickListener{
            textView.text = "i am clicked!"
        }

    }
}
